home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
getfil2r
/
form1.frm
< prev
Wrap
Text File
|
1999-08-16
|
18KB
|
765 lines
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5010
ClientLeft = 60
ClientTop = 345
ClientWidth = 8970
LinkTopic = "Form1"
ScaleHeight = 5010
ScaleWidth = 8970
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtNumPoints
Height = 285
Left = 1755
TabIndex = 18
Text = "1024"
Top = 4050
Width = 735
End
Begin VB.Frame Frame3
Caption = "Smoothing Algorithm"
Height = 1140
Left = 135
TabIndex = 15
Top = 90
Width = 2850
Begin VB.OptionButton Option1
Caption = "FFT"
Height = 195
Index = 1
Left = 225
TabIndex = 17
Top = 720
Width = 2040
End
Begin VB.OptionButton Option1
Caption = "Savitzky-Golay"
Height = 375
Index = 0
Left = 225
TabIndex = 16
Top = 270
Width = 2040
End
End
Begin VB.TextBox txtRandom
Height = 330
Left = 7200
TabIndex = 11
Text = "1"
Top = 4545
Width = 510
End
Begin VB.CommandButton CmdCreateData
Caption = "Reset Data"
Height = 375
Left = 3375
TabIndex = 1
Top = 4500
Width = 2445
End
Begin VB.PictureBox Pic1
BackColor = &H80000005&
Height = 4200
Left = 3195
ScaleHeight = 4140
ScaleWidth = 5535
TabIndex = 0
Top = 135
Width = 5595
End
Begin VB.Frame Frame2
Caption = "FFT Smooth"
Height = 2490
Left = 135
TabIndex = 7
Top = 1350
Width = 2895
Begin VB.HScrollBar HScroll1
Height = 285
Left = 135
Max = 1024
Min = 2
TabIndex = 8
Top = 1440
Value = 100
Width = 2535
End
Begin VB.Label Label4
Caption = "Move the scroll bar to smooth using the FFT algorithm"
Height = 510
Left = 315
TabIndex = 14
Top = 405
Width = 2355
End
Begin VB.Label Lblfft
AutoSize = -1 'True
Caption = "Frequency Cut-Off: 2 %"
Height = 195
Left = 585
TabIndex = 9
Top = 1125
Width = 1680
End
End
Begin VB.Frame Frame1
Caption = "Savitzky-Golay Smoothing"
Height = 2490
Left = 135
TabIndex = 2
Top = 1350
Width = 2895
Begin VB.CommandButton CmdSG2
Caption = "Cumulative Smoothing"
Enabled = 0 'False
Height = 375
Left = 180
TabIndex = 12
Top = 1935
Width = 2175
End
Begin VB.CommandButton Cmdsg1
Caption = "Smooth Data"
Height = 375
Left = 180
TabIndex = 6
Top = 1440
Width = 2175
End
Begin VB.ComboBox CboSavGol
Height = 315
Left = 1665
Style = 2 'Dropdown List
TabIndex = 5
Top = 405
Width = 1095
End
Begin VB.CheckBox ChkLog
Caption = "Log Data"
Height = 375
Left = 180
TabIndex = 4
ToolTipText = "Useful for positive data, spanning several orders of magnitude"
Top = 855
Width = 1905
End
Begin VB.Label Label1
Caption = "Smoothing Window:"
Height = 285
Left = 180
TabIndex = 3
Top = 450
Width = 1590
End
End
Begin VB.Label Label6
Caption = "For speed in FFT, use a power of 2 for the number of points"
Height = 420
Left = 45
TabIndex = 20
Top = 4500
Width = 2805
End
Begin VB.Label Label5
Caption = "Number of Points:"
Height = 240
Left = 270
TabIndex = 19
Top = 4095
Width = 1680
End
Begin VB.Label Label3
Caption = "(1 - 5)"
Height = 330
Left = 7830
TabIndex = 13
Top = 4590
Width = 915
End
Begin VB.Label Label2
Caption = "Randomness:"
Height = 330
Left = 6075
TabIndex = 10
Top = 4590
Width = 1680
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'Dynamic data arrays
Dim DataX() As Double
Dim DataY() As Double
Dim SmoothedY() As Double
Dim DataI() As Double
Private Const PI As Double = 3.14159265358979
Dim NP As Integer
Dim SmoothCount As Integer
'The matrix for the Savitzky-Golay Coefficents
'These are filled in the form load event
Dim SGCoef(1 To 11, 0 To 13) As Integer
Private Sub CmdCreateData_Click()
Dim i As Integer
Dim Ymin As Double, Ymax As Double
Dim RandFactor As Double
Randomize
Ymin = 0
Ymax = 0
RandFactor = Val(txtRandom)
NP = Val(txtNumPoints)
HScroll1.Max = NP
ReDim DataX(1 To NP)
ReDim DataY(1 To NP)
ReDim SmoothedY(1 To NP)
ReDim DataI(1 To NP)
For i = 1 To NP
DataX(i) = i
DataI(i) = 0
DataY(i) = Sin(i / NP * 4 * PI) + 0.5 * Sin(i / NP * 40 * PI) + RandFactor * Rnd + 4
If DataY(i) > Ymax Then Ymax = DataY(i)
If DataY(i) < Ymin Then Ymin = DataY(i)
Next
Pic1.ScaleLeft = 0
Pic1.ScaleWidth = NP
Pic1.ScaleTop = Ymax + Ymax * 0.1
Pic1.ScaleHeight = ((Ymax - Ymin)) * -1
GraphData DataY
SmoothCount = 0
If Option1(0).Value Then
Me.Caption = "Savitzky-Golay Smoothing"
Else
Me.Caption = "FFT Smoothing"
End If
CmdSG2.Enabled = False
HScroll1.SmallChange = NP / 100
HScroll1.LargeChange = NP / 20
End Sub
Private Sub Cmdsg1_Click()
Call SavGolSmooth(CboSavGol.ListIndex + 2, False)
Me.Caption = "Smoothed " & SmoothCount & " time"
GraphData SmoothedY
End Sub
Private Sub CmdSG2_Click()
Call SavGolSmooth(CboSavGol.ListIndex + 2, True)
Me.Caption = "Smoothed " & SmoothCount & " times"
GraphData SmoothedY()
End Sub
Private Sub Form_Activate()
Option1(0).Value = True
End Sub
Private Sub Form_Load()
CboSavGol.Clear
CboSavGol.AddItem "5 point"
CboSavGol.AddItem "7 point"
CboSavGol.AddItem "9 point"
CboSavGol.AddItem "11 point"
CboSavGol.AddItem "13 point"
CboSavGol.AddItem "15 point"
CboSavGol.AddItem "17 point"
CboSavGol.AddItem "19 point"
CboSavGol.AddItem "21 point"
CboSavGol.A